t = int(input())
s = []
for i in range(t):
cost = input()
cost = cost.split(' ')
for j in range(len(cost)):
cost[j] = int(cost[j])
cost.sort()
r = 0
l = 0
n = int(input())
for j in range(n):
y = list(input())
r += int(y[0])
l += int(y[2])
if r > l:
r = r * int(cost[0])
l = l * int(cost[1])
else:
r = r * int(cost[1])
l = l * int(cost[0])
a = l + r
s.append(a)
for i in range(len(s)):
print(s[i])
1326B - Maximums | 1635C - Differential Sorting |
961A - Tetris | 1635B - Avoid Local Maximums |
20A - BerOS file system | 1637A - Sorting Parts |
509A - Maximum in Table | 1647C - Madoka and Childish Pranks |
689B - Mike and Shortcuts | 379B - New Year Present |
1498A - GCD Sum | 1277C - As Simple as One and Two |
1301A - Three Strings | 460A - Vasya and Socks |
1624C - Division by Two and Permutation | 1288A - Deadline |
1617A - Forbidden Subsequence | 914A - Perfect Squares |
873D - Merge Sort | 1251A - Broken Keyboard |
463B - Caisa and Pylons | 584A - Olesya and Rodion |
799A - Carrot Cakes | 1569B - Chess Tournament |
1047B - Cover Points | 1381B - Unmerge |
1256A - Payment Without Change | 908B - New Year and Buggy Bot |
979A - Pizza Pizza Pizza | 731A - Night at the Museum |